﻿using Heng.Elements.Core.Model.Infrastructure.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heng.Elements.Core.Model.Infrastructure.Repositories
{
    /// <summary>
    /// Implemented by entity repositories.
    /// </summary>
    public interface IEntityRepository
    {
        /// <summary>
        /// Repository context.
        /// </summary>
        IEntityRepositoryContext RepositoryContext { get; set; }
    }

    /// <summary>
    /// Implemented by entity repositories.
    /// </summary>
    /// <typeparam name="TEntity"> Entity type. </typeparam>
    public interface IEntityRepository<TEntity> : IEntityRepository
        where TEntity : IEntity
    {
        /// <summary>
        /// Get entity by ID.
        /// </summary>
        /// <param name="id"> Entity ID. </param>
        /// <returns> Entity. </returns>
        TEntity GetById(long id);

        /// <summary>
        /// Get all entities.
        /// </summary>
        /// <returns> All entities. </returns>
        IEnumerable<TEntity> GetAll();

        /// <summary>
        /// Add entity.
        /// </summary>
        /// <param name="entity"> Entity instance. </param>
        void Add(TEntity entity);
        
        /// <summary>
        /// Save entity.
        /// </summary>
        /// <param name="entity"> Entity instance. </param>
        void Save(TEntity entity);

        /// <summary>
        /// Delete entity.
        /// </summary>
        /// <param name="entity"> Entity instance. </param>
        void Delete(TEntity entity);

        /// <summary>
        /// Delete entity by ID.
        /// </summary>
        /// <param name="id"> Entity ID. </param>
        void Delete(long id);

        /// <summary>
        /// Save changes on current repository.
        /// </summary>
        void SaveChanges();
    }
}
